using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WeaponEventSubscriber<TArgs>:EventSubscriber<TArgs> where TArgs : WeaponEventArgs {
	protected Dictionary<Mob,System.EventHandler<TArgs>> singleSubscribtionsMob = new Dictionary<Mob,System.EventHandler<TArgs>>();

	public void SubscribeMobSingle(Mob mob,System.EventHandler<TArgs> handler) {
		if(singleSubscribtionsMob.ContainsKey(mob)) {
			singleSubscribtionsMob[mob]+=handler;
		} else {
			singleSubscribtionsMob.Add(mob,handler);
		}
	}
	public void UnsubscribeMobSingle(Mob mob,System.EventHandler<TArgs> handler) {
		if(!singleSubscribtionsMob.ContainsKey(mob)) return;

		singleSubscribtionsMob[mob]-=handler;
		if(singleSubscribtionsMob[mob]==null)
			singleSubscribtionsMob.Remove(mob);

	}
	public override void TargetEventHandler(object sender,TArgs e) {
		base.TargetEventHandler(sender,e);
		if(e.senderMob&&singleSubscribtionsMob.ContainsKey(e.senderMob))
			singleSubscribtionsMob[e.senderMob].Invoke(sender,e as TArgs);
	}

}

public static class WeaponEventHelper {

	public static WeaponEventSubscriber<ShootEventArgs> ammoConsumptionDeciding= new WeaponEventSubscriber<ShootEventArgs>();
	public static WeaponEventSubscriber<ShootEventArgs> shooting= new WeaponEventSubscriber<ShootEventArgs>();
	public static WeaponEventSubscriber<ShootEventArgs> shot= new WeaponEventSubscriber<ShootEventArgs>();
	public static WeaponEventSubscriber<ShootEventArgs> projectileDeciding= new WeaponEventSubscriber<ShootEventArgs>();
	public static WeaponEventSubscriber<BurstDecidingEventArgs> burstDeciding= new WeaponEventSubscriber<BurstDecidingEventArgs>();
	public static WeaponEventSubscriber<ReloadEventArgs> clipSizeDeciding= new WeaponEventSubscriber<ReloadEventArgs>();
	public static WeaponEventSubscriber<ReloadEventArgs> reloading= new WeaponEventSubscriber<ReloadEventArgs>();
	public static WeaponEventSubscriber<ReloadStartEventArgs> reloadStart= new WeaponEventSubscriber<ReloadStartEventArgs>();

	static WeaponEventHelper() {
		Weapon.AmmoConsumptionDeciding+=ammoConsumptionDeciding.TargetEventHandler;
		Weapon.Shooting+=shooting.TargetEventHandler;
		Weapon.Shot+=shot.TargetEventHandler;
		Weapon.ProjectileDeciding+=projectileDeciding.TargetEventHandler;
		Weapon.BurstDeciding+=burstDeciding.TargetEventHandler;
		Weapon.ClipSizeDeciding+=clipSizeDeciding.TargetEventHandler;
		Weapon.Reloading+=reloading.TargetEventHandler;
		Weapon.ReloadStart+=reloadStart.TargetEventHandler;
	}

}